/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Raytracing;

import processing.core.PApplet;
import processing.core.PVector;

/**
 *
 * @author Matt
 */
public class Sampling {

    
    public static void cosineSampleHemisphere(PVector sample, float u1, float u2) {

        double r = Math.sqrt(u1);

        double theta = 2.0 * Math.PI * u2;

        sample.x = (float) (Math.cos(theta) * r);
        sample.y = (float) (Math.sin(theta) * r);
        sample.z = (float) Math.sqrt(PApplet.max(0.f, 1 - u1));
    }

    public static PVector uniformSampleHemisphere(PVector sample, float u1, float u2) {

        

        double r = Math.sqrt(1.f - u1 * u1);

        double phi = 2.0 * Math.PI * u2;

        sample.x = (float) (Math.cos(phi) * r);
        sample.y = (float) (Math.sin(phi) * r);
        sample.z = u1;

        return sample;

    }
}
